package org.monster.boot;

import org.monster.app.AppContext;
import org.monster.context.core.manager.StringManager;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * 服务器中介者
 */
public class ServiceMediator implements Mediator {

    /**
     * Dos命令接收类
     */
    private static final StringManager sm = StringManager.getManager(Constants.Package);
    /**
     * 日志器
     */
    private static final Logger logger = Logger.getLogger(ServiceMediator.class.getName());
    /**
     * Dos容器代理
     */
    private static final DosContainerProxy proxy = new DosContainerProxy(new AppContext(),
            new DosValidate());
    /**
     * Dos接收器
     */
    private static final DosReceiver dosReceiver = new DosReceiver(proxy);
    /**
     * Dos发送器
     */
    private static final DosSender dosSender = new DosSender();
    /**
     * 管道连接器
     */
    private static final PipedConnector connector = new PipedConnector();
    /**
     * Socket接收类
     */
    private static final SocketReceiver socketReceiver = new SocketReceiver();
    /**
     * Dos执行器
     */
    private static final DosExecutor dosExecutor = new DosExecutor(socketReceiver);

    /**
     * 介绍
     */
    @Override
    public void introduce() {
        dosExecutor.start();
        try {
            connector.connect(dosReceiver, dosSender);
        } catch (IOException ex) {
            logger.log(Level.SEVERE, sm.getString("ServiceMediator.introduce.connectEx"));
        }
        dosSender.start();
        dosReceiver.start();
        socketReceiver.start();
    }
}
